package com.lggry.array.method;

public class MethodDemo1 {
    public static void main(String[] args) {
        int sum = getSum(1,2);
        System.out.println(sum);
        printHelloWorld();
        System.out.println(getCode(4));
    }

    //定义一个方法，求任意两个整数的和并返回
    public static int getSum(int a, int b) {
        return a + b;
    }

    //需求：打印3行HelloWorld,不需要参数，也不需要返回值
    //注意：如果方法没有返回值，返回值类型必须生命void
    //无参数，无返回值类型
    public static void printHelloWorld() {
        System.out.println("HelloWorld");
        System.out.println("HelloWorld");
        System.out.println("HelloWorld");
    }

    //创建一个方法，返回指定位数的随机数字验证码
    public static String getCode(int length) {
        String str = "0123456789";
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int index = (int) (Math.random() * str.length());
            char c = str.charAt(index);
            sb.append(c);
        }
        return sb.toString();
    }

}
